// pages/goodsManagement/cloudGoodsComment/cloudGoodsComment.js
const Controllers = require('../../controllers/Controller.js').controller;
const formatTime2 = require('../../../utils/util.js').formatTime2
Page({

  /**
   * 页面的初始数据
   */
  data: {
    commentList: [],
    pageNumber: 1,
    goodsId: '',
    page: {
      pageNumber: 1,
      pageSize: 10
    },
    list: [],
    totalRow: 0,
    isLoading: false,
    lastPage: true
  },

  //获取评论列表
  goodsCommentPage() {
    var that = this;
    var page = that.data.page;
    if (that.data.isLoading) {
      return;
    }
    that.data.isLoading = true;
    wx.showLoading();
    var goodsId = that.data.goodsId;
    var params = { ...page, goodsId };
    Controllers.goodsCommentPage(params).then(res => {
      console.log('goodsCommentPage--res==', res);
      const { code, data, desc } = res;
      const { list, totalRow, lastPage } = data;
      if (page.pageNumber === 1) {
        that.data.list = list;
      } else {
        that.data.list = that.data.list.concat(list);
      }
      that.setData({
        list: that.data.list,
        totalRow,
        lastPage,
        isLoading: false
      });
      wx.hideLoading();
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      goodsId: options.id
    })
    this.goodsCommentPage()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    if (that.data.isLoading || that.data.lastPage) {
      return;
    }
    that.data.page.pageNumber += 1;
    that.goodsCommentPage();
  },
  /**
   * 用户点击右上角分享
   */
   // onShareAppMessage: function () {

  // }
})